package com.wgj.android.http.weixin;

import android.os.Build;
import android.support.annotation.RequiresApi;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wgj.android.http.weixin.model.SendResult;
import com.wgj.android.http.weixin.model.WXFriend;
import com.wgj.android.http.weixin.model.WXInfo;



import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Predicate;

/**
 * Created by Administrator on 2017/10/19.
 */
public class WXFormatUtil {
    public  static boolean checkIsMyFriend(SendResult result){
        if(result.getStatus().equals("4")){
            return false;
        }else {
            return true;
        }
    }

    public static void filtrateMyFriend(List<SendResult> list){

        for (int i = list.size() - 1; i >= 0; i--) {
            if (!list.get(i).getStatus().equals("4")){
                list.remove(i);
            }
        }
    }

    public static String getRand15Num(){
        return new BigDecimal(100000000000000l)
                .add(new BigDecimal(900000000000000l)
                        .multiply(new BigDecimal(Math.random())))
                .setScale(0,BigDecimal.ROUND_CEILING).toString();
    }

    public static String getNDate(){
        return "" + ~Long.parseLong("" + (-(int)new Date().getTime()));
    }

    public static List getAllName(JSONObject jsonObject, WXInfo wxInfo) {
        List<WXFriend> list = null;
        try {

            JSONArray jsonArray = jsonObject.getJSONArray("MemberList");

            list = new LinkedList<WXFriend>();

            for (int i = 0; i < jsonArray.size(); i++) {
                WXFriend temp = new WXFriend();
                JSONObject jsonObject1 = (JSONObject) jsonArray.get(i);
                temp.setNickName(jsonObject1.getString("NickName"));
                temp.setUserName(jsonObject1.getString("UserName"));
                temp.setVerifyFlag(jsonObject1.getString("VerifyFlag"));
                temp.setHeadImgUrl(jsonObject1.getString("HeadImgUrl"));

                //特殊微信昵称
                temp.setNickName(temp.getNickName().equals("")? "未填写":temp.getNickName());

                list.add(temp);
            }

            for (int i = list.size() - 1; i >= 0; i--) {
                if (!list.get(i).getVerifyFlag().equals("0")){
                    list.remove(i);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }




    public static List removeDuplicate(List list) {
        HashSet h = new HashSet(list);
        list.clear();
        list.addAll(h);
        return list;
    }



    public static String getRandIDNum(){
        return new BigDecimal(new Date().getTime()).toString() + ((int)(1000 + Math.random() * 9000));
    }


}
